package com.example.peanutsubway.util;

import java.util.List;

/**
 * @Author：liulei
 * @Version：1.0
 * @Date：2021/9/30-14:53
 * @Since:jdk1.8
 * @Description:
 */
public class PageInfo<T> {

    private Integer nowPage;
    private Integer pageNum;
    private Integer startIndex;
    private Integer totalNum;// 总条数
    private Integer totalPage;// 总页数
    private List<T> dataList;// 分页查询到的数据

    private Integer prvePage;
    private Integer nextPage;
    private Boolean hasNext;
    private Boolean hasPrve;

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public PageInfo() {
    }

    /**
     * 分页信息
     *
     * @param nowPageStr
     * @param pageNumStr
     * @param totalNum
     */
    public PageInfo(String nowPageStr, String pageNumStr, Integer totalNum) {
        Integer nowPage = DataConvert.stringConvertInteger(nowPageStr);
        Integer pageNum = DataConvert.stringConvertInteger(pageNumStr);

        this.nowPage = nowPage <= 0 ? 1 : nowPage;
        this.pageNum = pageNum <= 0 ? 3 : pageNum;
        this.totalNum = totalNum;

        this.totalPage = this.totalNum % this.pageNum == 0 ? this.totalNum / this.pageNum : this.totalNum / this.pageNum + 1;
        this.nowPage = this.nowPage > this.totalPage ? this.totalPage : this.nowPage;
        this.startIndex = (this.nowPage - 1) * this.pageNum;
    }

    public Integer getNowPage() {
        return nowPage;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public Integer getTotalNum() {
        return totalNum;
    }

    public Integer getTotalPage() {
        return totalPage;
    }
}
